//
//  YZEmptyView.m
//  VET
//
//  Created by Lam BG on 2018/7/10.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZEmptyView.h"
#import "YZStatementHeader.h"

// 第三方
#import "TBCityIconFont.h"

#import "YZRouter+AutoVC.h"

@interface YZEmptyView ()

@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UIImageView *infoIV;

@property (weak, nonatomic) IBOutlet UILabel *infoLabel;

@property (weak, nonatomic) IBOutlet UIButton *actionBtn;

@property (copy, nonatomic) yz_emptyBlock actionBlock;

@end

@implementation YZEmptyView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.bgView.userInteractionEnabled = NO;
}

- (void)setupInfo:(NSString*)info actionTips:(NSString*)actionTips action:(yz_emptyBlock)actionBlock {
    
    self.infoLabel.text = info;
    [self.actionBtn setTitle:actionTips forState:(UIControlStateNormal)];
    self.actionBlock = actionBlock;
}

#pragma mark - event actions

// 拦截当前 view 的事件
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    if (self.isHidden == NO) {
        
        CGPoint newPoint = [self convertPoint:point toView:self.actionBtn];
        if ( [self.actionBtn pointInside:newPoint withEvent:event]) {
            
            return self.actionBtn;
            
        } else {
            
            UIView *view = [super hitTest:point withEvent:event];
            if (view) view.userInteractionEnabled = NO;
            
            return view;
        }
        
    } else {
        
        return [super hitTest:point withEvent:event];
    }
}

- (IBAction)actionClicked:(id)sender {
    
    // 跳转到新建任务
    [[YZRouter sharedInstance] yz_atuoPush:@"dwNewDailyWork"];
    if (self.actionBlock) {
        
        self.actionBlock();
    }
}

@end
